package com.hkfn.rfb.common.view;

import android.content.Context;
import android.os.Bundle;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.hkfn.rfb.common.activity.BaseActivity;
import com.hkfn.rfb.common.bean.BannerModel;
import com.hkfn.rfb.common.utils.GildeUtils;
import com.hkfn.rfb.common.utils.Utils;

public class MenuItemView extends LinearLayout {
    private Context context;

    public MenuItemView(Context context) {
        super(context);
        this.context = context;
        setOrientation(VERTICAL);
        setGravity(Gravity.CENTER);
    }

    public MenuItemView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        this.context = context;
        setOrientation(VERTICAL);
    }

    public MenuItemView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.context = context;
        setOrientation(VERTICAL);
    }

    public void setBannerModel(final BannerModel bannerModel){
        if (null == bannerModel){
            return;
        }
        ImageView imageView = new ImageView(context);
        GildeUtils.loadImage(context, imageView, bannerModel.getImg());
        this.addView(imageView, new ViewGroup.LayoutParams(Utils.dip2px(context, 40), Utils.dip2px(context, 40)));
        TextView textView = new TextView(context);
        textView.setText(bannerModel.getTitle());
        textView.setTextSize(12);
        LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        layoutParams.setMargins(0, Utils.dip2px(context, 3), 0, 0);
        this.addView(textView, layoutParams);
        this.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (context instanceof BaseActivity){
                    Bundle bundle = new Bundle();
                    ((BaseActivity)context).setClickAction(bannerModel);
                }
            }
        });
    }


}
